<?php
if ($_GET['confirm']) {
	echo "<h2>Thank you for registering!!</h2>";
	echo "<div class=\"confirmation_details\"><p>You have registered for the " . $event->event_name . "</p>";
	echo "<p>Your confirmation code is: " . $event->id . "-" . $_GET['confirm']. "</p></div>";
} else {
	echo "<h2>" . $event->event_name . "</h2>";

	if (isset($_GET['em_error'])) {
		echo "<div class=\"confirmation_details\"><p>It looks like you're already registered for this event.</p></div>";
	}
}
?>
<dl id="event_info">
	<dt>About this event:</dt>
	<dd><?php echo "<p>" . preg_replace("/\r\n\r\n/", "</p>\r\n<p>", $event->short_description) . "</p>" ?></dd>
	<dt>Date:</dt>
	<dd><?php echo mysql2date("F d, Y", $event->event_start) ?></dd>
	<dt>Time:</dt>
	<dd><?php echo mysql2date("g:i A", $event->event_start) ?></dd>
	<dt>Location:</dt>
	<dd><?php echo $event->address1 ?>
		<?php if (!empty($event->address2)) echo "<br />" . $event->address2; ?>
		<?php if (!empty($event->city)) echo "<br />" . $event->city . ", "; ?><?php echo $event->state ?> <?php echo $event->zip ?>
	</dd>
</dl>

<?php

$user = wp_get_current_user();
//print_r($user);

if (!$_GET['confirm']) {
	if (strtotime($event->registration_start) > time() || strtotime($event->registration_end) < time()) {
		echo "<h3>Registration is currently not available for this event.</h3>";
	} elseif ($wpdb->get_var("SELECT count(*) from $em_registration_table where event_id = '$event->id'") >= $event->registration_limit) {
		echo "<h3>Registration is currently full.</h3>";
	} elseif ($event->login_required == "Y" && !is_user_logged_in()){
		$redirect_url = get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']);
		echo '<h3>You must <a href="' . $redirect_url . '">login</a> to register for this event.</h3>';
	} else {
?>
<p class="em-form-instructions"><strong>Please complete the registration form below to participate in this event.</strong></p>
<form class="registerForm" id="registerForm" action="" method="post">
	<input type="hidden" name="event_id" value="<?php echo $event->id ?>"/>
	<input type="hidden" name="em_register_form" value="1"/>
	<table>
		<tr><th>E-Mail Address</th><td><input type="text" class="r" id="email_address" name="email_address" title="E-Mail Address" size="30" value="<?php echo $user->user_email ?>"/></td></tr>
		<tr><th>First Name</th><td><input type="text" class="r" id="first_name" name="first_name" size="30" title="First Name" value="<?php echo $user->first_name ?>" /></td></tr>
		<tr><th>Last Name</th><td><input type="text" class="r" id="last_name" name="last_name" title="Last Name" size="30" value="<?php echo $user->last_name ?>" /></td></tr>
		<tr><th>Address</th><td><input type="text" class="r" id="address1" name="address1" title="Address" size="30"/><br /><br /><input type="text" id="address2" name="address2" size="30"/></td></tr>
		<tr><th>City</th><td><input type="text" class="r" id="city" name="city" title="City" size="30"/></td></tr>
		<tr><th>State</th><td><input type="text" class="r" id="state" name="state" title="State" size="2" maxlength="2"/></td></tr>
		<tr><th>Zip</th><td><input type="text" class="r" id="zip" name="zip" title="Zip" size="10"/></td></tr>
		<tr><th>Phone</th><td><input type="text" class="r" id="phone" name="phone" title="Phone" size="15"/></td></tr>
		<?php
		$questions = $wpdb->get_results("SELECT * from `$em_question_table` where event_id = '$event->id' order by sequence");
		if ($questions)
		foreach($questions as $question) {
			$class = ('alternate' == $class) ? '' : 'alternate';
		?>
		<tr class="<?php echo $class ?>"><th><?php echo $question->question ?></th><td><?php em_render_form_field($question) ?></td></tr>
		<?php } ?>
	</table>
	<p><input type="submit" name="submit" value="Register!"/></p>
</form>

<?php
	}//end checking event status
}// end not confirm
?>